#pragma once
#include <string>
using namespace std;

enum
{
  DivZero = 1,
  ModZero,
  Unknow
};

class Task
{
public:
  Task(int data1, int data2, char opra)
      : _data1(data1), _data2(data2), _opra(opra), _result(0), _exitcode(0)
  {
  }

  void run()
  {
    switch (_opra)
    {
    case '+':
      _result = _data1 + _data2;
      break;
    case '-':
      _result = _data1 - _data2;
      break;
    case '*':
      _result = _data1 * _data2;
      break;
    case '/':
    {
      if (_data2 == 0)
        _exitcode = DivZero;
    }
    break;
    case '%':
    {
      if (_data2 == 0)
        _exitcode = ModZero;
    }
    break;
    default:
      _exitcode = Unknow;
      break;
    }
  }

  string getTask()
  {
    string str = "发布任务: ";
    str += to_string(_data1) + " ";
    str += _opra;
    str += " " + to_string(_data2) + " ";
    str += "=?";
    return str;
  }

  string getResult()
  {
    string str = "执行任务: ";
    str += to_string(_data1) + " ";
    str += _opra;
    str += " " + to_string(_data2) + " ";
    str += "= ";
    str += to_string(_result);
    str += " [exitcode: ";
    str += to_string(_exitcode);
    str += "]";
    return str;
  }

  ~Task()
  {
  }

private:
  int _data1;
  int _data2;
  char _opra;

  int _result;
  int _exitcode;
};
